package com.gitee.wsl.evaluator.token

class CharToken(val ch: Char, lineNo: Int, startIndex: Int) :
    AbstractToken<Char>(ch.toString(), lineNo, startIndex) {
    override val startIndex: Int = 0

    override val type:Token.TokenType = Token.TokenType.Char

    override fun getValue(env: Map<String, Any?>?): Char {
        return this.ch
    }

    override fun hashCode(): Int {
        val prime = 31
        var result = super.hashCode()
        result = prime * result + ch.code
        result = prime * result + this.startIndex
        return result
    }


    override fun equals(obj: Any?): Boolean {
        if (this === obj) {
            return true
        }
        if (obj==null || !super.equals(obj)) {
            return false
        }

        if (this::class != obj::class) {
            return false
        }
        val other = obj as CharToken
        if (this.ch != other.ch) {
            return false
        }

        if (this.startIndex != other.startIndex) {
            return false
        }

        return true
    }

}